<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>{$lang.add}|{$lang.edit}</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<include file="common/ace-tag"/>
	</head>
	<link rel="stylesheet" href="/static/plugin/ace/css/chosen.css" />
	<script src="/static/plugin/ace/js/chosen.jquery.min.js"></script>
	<script src="/static/plugin/ace/js/jquery.autosize.min.js"></script>
	<script src="/static/plugin/ace/js/jquery.inputlimiter.1.3.1.min.js"></script>
	<style>
		body{
			background-color:#fff
		}
		.yui_right{
			float: right;
			margin-bottom: 10px;
		}
	</style>
	<body >
	<div class="layui-form">
		<div class="widget-main">
			<input type="hidden" name="id" value="{$data.id}"/>
			<div>
				<label >{$lang_field['tag.name']}</label>
				<input type="text" name="name"  placeholder="{$lang_field['tag.name']}" class="form-control" value="{$data.name}"/>
				<br>
			</div>

			<div>
				<label >{$lang_field['tag.code']}</label>
				<input type="text" name="code" <if condition="$method eq 'edit'">readonly</if> placeholder="{$lang_field['tag.code']}" class="form-control" value="{$data.code}"/>
				<br>
			</div>


			<div>
				<label>{$lang_field['category']}</label>
				<select class="form-control" name="category" lay-filter="category" lay-search>
					<foreach name="category_list" item="val" key="key">
						<if condition="$data.category==$key">
							<option value="{$key}" selected>{$val}</option>
							<else/>
							<option value="{$key}">{$val}</option>
						</if>
					</foreach>
				</select>
				<br>
			</div>

			<div>
				<label >{$lang_field['sort']}</label>
				<input type="number" name="sort" placeholder="{$lang_field['sort']}" class="form-control" value="{$data.sort|default=$lastSort}"/>
				<br>
			</div>

			<div >
				<label >{$lang_field.status}</label>
				<select class="form-control" name="status">
					<eq name="data.status|default=1" value="1">
						<option value="1" selected>{$lang_field.on}</option>
						<option value="2">{$lang_field.off}</option>
						<else/>
						<option value="2" selected>{$lang_field.off}</option>
						<option value="1">{$lang_field.on}</option>
					</eq>
				</select>
				<br>
			</div>

			<button class="btn btn-primary yui_right" id="save">
				<i class="icon-plus align-top bigger-125"></i>
				{$lang.save}
			</button>


		</div>
	</div>

	</body>

	<script>
		$(function () {

            layui.use(['form'], function(){
                let form = layui.form;
                form.on('select(category)', function(data){
                    let loading = layer.load(1, {
                        shade: [0.1,'#fff']
                    });
                    let category =data.value;
                    $.post("{$__url}",
                        {
                            category:category,
                            change:true,
                        },
                        function(data,status){
                            if (data['code']==1){
                                $("input[name='sort']").val(data['data']);
                            }else{
                                layer.msg(data['msg']);
                            }
                            layer.close(loading);
                        }, "json"
                    );
                });
            });

            $(".chosen-select").chosen();
            $('textarea[class*=autosize]').autosize({append: "\n"});
            $('textarea.limited').inputlimiter({
                remText: '%n character%s remaining...',
                limitText: 'max allowed : %n.'
            });

            //新增
            $("#save").on('click' , function(){
                let id=$("input[name='id']").val();
                let name=$("input[name='name']").val();
                let code=$("input[name='code']").val();
                let category=$("select[name='category']").val();
                let sort=$("input[name='sort']").val();
                let status=$("select[name='status']").val();
                let loading = layer.load(1, {
                    shade: [0.1,'#fff']
                });
				//ajax提交数据
                $.post("{$__url}",
                    {
                        method:'{$method}',
                        id:id,
                        name:name,
                        code:code,
                        category:category,
                        sort:sort,
                        status:status
                    },
                    function(data,status){
                        if (data['code']==1){
                            layer.open({
                                title: '{$lang.notice}',
                                content: '{$lang.op_success}'
                                ,yes: function(index, layero){
                                    //关闭本子页面 & 触发重新查询
                                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                                    let node = window.parent.document.getElementById("npe_search");
                                    node.click();
                                }
                            });
						}else{
                            layer.msg(data['msg']);
						}
                        layer.close(loading);
                	}, "json"
                );
            });

        });
	</script>

</html>
